import { LoginCenterApi } from '../api/serves';
import store from '../store';
import tool from '../common/utils/tool.js';
export default {
  install(app) {
    app.mixin({
      data() {
        return {
          ASSETSURL: 'https://cdn1.vrupup.com/s/1500/img/',
          isOverShare: false,
          textList: [],
        };
      },
      onLoad(options) {
        // #ifdef MP-WEIXIN
        uni.showShareMenu({});
        // this.getUserInfo();
        // #endif
        // #ifdef H5
        console.log('123', options);
        tool.tool.storage('token', {
          token: options.token,
        });
        // #endif
      },
      methods: {
        async paramList() {
          let { code, data, msg } = await LoginCenterApi.paramList();
          if (code != 1) return;
          this.textList = data;
          console.log(this.textList, 'textList');
        },
        async goWeb() {
          // let { code, data, msg } = await ()
        },

        swiperClick(item) {
          console.log('轮播点击', item);
          item.jumpType = 2;
          if (!item.jump_url || item.is_jump == 0) return;
          switch (item.jumpType) {
            case 2:
              if (!item.jump_url.startsWith('/')) {
                item.jump_url = '/' + item.jump_url;
              }
              console.log(item.jump_url);
              uni.navigateTo({
                url: item.jump_url,
                fail: (err) => {
                  uni.switchTab({
                    url: item.jump_url,
                  });
                },
              });
              break;
            case 3:
              uni.navigateToMiniProgram({
                appId: item.appId,
                path: item.jump_url,
                success: (res) => {
                  // 打开成功
                  console.log('打开成功', res);
                },
                fail: (err) => {
                  console.log(err);
                },
              });
              break;
            case 5:
              uni.openChannelsActivity({
                finderUserName: item.spId,
                feedId: item.feedId,
                success(res) {
                  console.log(res);
                },
              });
              break;
            case 4:
              uni.navigateTo({
                url:
                  '/pages/web-page/web-page?url=' +
                  encodeURIComponent(JSON.stringify(item.jump_url)),
              });
              break;
          }
        },
        async getUserInfo() {
          const { code, data, msg } = await LoginCenterApi.get_user_detail();
          if (code != 1) return;
          store.commit('setUserInfo', data);
          tool.tool.storage('userInfo', data);
          this.paramList();
        },
      },
    });
  },
};
